package com.kim.rssreader.adapter;

import java.util.List;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

public class ColumnViewPageAdapter extends PagerAdapter {

	List<View> views;

	public ColumnViewPageAdapter(List<View> views) {
		this.views = views;
		if (this.views == null) {
			throw new IllegalArgumentException("views can not be null");
		}
	}

	public void resetData(List<View> views) {

		if (this.views != null) {
			this.views.clear();
			this.views = null;
		}

		this.views = views;
		if (this.views == null) {
			throw new IllegalArgumentException("views can not be null");
		}
	}

	@Override
	public void destroyItem(View container, int position, Object object) {
		if (position >= views.size()) {
			return;
		}
		((ViewPager) container).removeView(views.get(position));
	}

	@Override
	public Object instantiateItem(View container, int position) {
		((ViewPager) container).addView(views.get(position), 0);
		return views.get(position);
	}

	@Override
	public int getCount() {
		return views.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	@Override
	public int getItemPosition(Object object) {
		return PagerAdapter.POSITION_NONE;
	}

}
